﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Tools.Helper
{
    /// <summary>
    /// 字节帮助类
    /// </summary>
    public class ByteHelper
    {
        /// <summary>
        /// 字节数组转16进制字符串
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public static string ToHex(byte[] array)
        {
            if (array == null) return string.Empty;
            string hex = string.Empty;
            for (int i = 0; i < array.Length; i++)
            {
                hex += ByteToHex(array[i]);
            }
            return hex;
        }

        public static string ByteToHex(byte v)
        {
            string result = Convert.ToString(v, 16);// result="61"
            return result;
        }
    }
}
